import { Controller } from '@nestjs/common';
import { WeatherService } from './weather.service';
import {
  Crud,
  CrudController,
  CrudRequest,
  Override,
  ParsedBody,
  ParsedRequest,
} from '@dataui/crud';
import { Weather } from '@/module/weather/entities/weather.entity';
import { CreateWeatherDto } from '@/module/weather/dto/create-weather.dto';

@Crud({
  model: {
    type: Weather,
  },
  routes: {
    only: ['getOneBase', 'createOneBase', 'getManyBase'],
  },
  query: {
    join: {
      testingMachine: {
        eager: true,
      },
    },
  },
  dto: {
    create: CreateWeatherDto,
  },
})
@Controller('weather')
export class WeatherController implements CrudController<Weather> {
  constructor(public service: WeatherService) {}

  @Override()
  async createOne(
    @ParsedRequest() req: CrudRequest,
    @ParsedBody() dto: CreateWeatherDto,
  ): Promise<any> {
    return this.service.createOneById(req, dto);
  }
}
